package com.app.biz.service.impl;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import cn.hutool.core.util.IdUtil;
import com.app.biz.domain.BizZdCompanyInfo;
import com.app.biz.mapper.BizZdCompanyInfoMapper;
import com.app.biz.service.IBizZdCompanyInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.crypto.Data;


/**
 * 重点企业信息服务Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-09-09
 */
@Service
public class BizZdCompanyInfoServiceImpl implements IBizZdCompanyInfoService
{
    @Autowired
    private BizZdCompanyInfoMapper bizZdCompanyInfoMapper;

    /**
     * 查询重点企业信息服务
     * 
     * @param baseId 重点企业信息服务主键
     * @return 重点企业信息服务
     */
    @Override
    public BizZdCompanyInfo selectBizZdCompanyInfoByBaseId(String baseId)
    {
        return bizZdCompanyInfoMapper.selectBizZdCompanyInfoByBaseId(baseId);
    }

    /**
     * 查询重点企业信息服务列表
     * 
     * @param bizZdCompanyInfo 重点企业信息服务
     * @return 重点企业信息服务
     */
    @Override
    public List<BizZdCompanyInfo> selectBizZdCompanyInfoList(BizZdCompanyInfo bizZdCompanyInfo)
    {
        return bizZdCompanyInfoMapper.selectBizZdCompanyInfoList(bizZdCompanyInfo);
    }

    /**
     * 新增重点企业信息服务
     * 
     * @param bizZdCompanyInfo 重点企业信息服务
     * @return 结果
     */
    @Override
    public int insertBizZdCompanyInfo(BizZdCompanyInfo bizZdCompanyInfo)
    {
        bizZdCompanyInfo.setBaseId(IdUtil.simpleUUID());
        bizZdCompanyInfo.setBaseCreateTime(new Date());
        return bizZdCompanyInfoMapper.insertBizZdCompanyInfo(bizZdCompanyInfo);
    }

    /**
     * 修改重点企业信息服务
     * 
     * @param bizZdCompanyInfo 重点企业信息服务
     * @return 结果
     */
    @Override
    public int updateBizZdCompanyInfo(BizZdCompanyInfo bizZdCompanyInfo)
    {
        return bizZdCompanyInfoMapper.updateBizZdCompanyInfo(bizZdCompanyInfo);
    }

    /**
     * 批量删除重点企业信息服务
     * 
     * @param baseIds 需要删除的重点企业信息服务主键
     * @return 结果
     */
    @Override
    public int deleteBizZdCompanyInfoByBaseIds(String[] baseIds)
    {
        return bizZdCompanyInfoMapper.deleteBizZdCompanyInfoByBaseIds(baseIds);
    }

    /**
     * 删除重点企业信息服务信息
     * 
     * @param baseId 重点企业信息服务主键
     * @return 结果
     */
    @Override
    public int deleteBizZdCompanyInfoByBaseId(String baseId)
    {
        return bizZdCompanyInfoMapper.deleteBizZdCompanyInfoByBaseId(baseId);
    }

    @Override
    public BizZdCompanyInfo mobileGetById(String id) {
        BizZdCompanyInfo bizZdCompanyInfo = bizZdCompanyInfoMapper.selectBizZdCompanyInfoByBaseId(id);
        if(bizZdCompanyInfo != null){
            String companyName = bizZdCompanyInfo.getCompanyName();
            BizZdCompanyInfo queryParams = new BizZdCompanyInfo();
            queryParams.setCompanyName(companyName);
            queryParams.setMonth(bizZdCompanyInfo.getMonth());
            List<BizZdCompanyInfo> bizZdCompanyInfos = bizZdCompanyInfoMapper.selectBizZdCompanyInfoCustomList(queryParams);
            if(bizZdCompanyInfos != null && bizZdCompanyInfos.size() > 0){
                BizZdCompanyInfo bizZdCompanyInfo1 = bizZdCompanyInfos.get(0);
                if(bizZdCompanyInfo1 != null){
                    BigDecimal lrhj = bizZdCompanyInfo1.getLrhj() == null ? BigDecimal.ZERO : bizZdCompanyInfo1.getLrhj();
                    BigDecimal gyzcz = bizZdCompanyInfo1.getGyzcz() == null ? BigDecimal.ZERO : bizZdCompanyInfo1.getGyzcz();
                    BigDecimal lrze = bizZdCompanyInfo1.getLrze() == null ? BigDecimal.ZERO : bizZdCompanyInfo1.getLrze();
                    BigDecimal xyczyc = bizZdCompanyInfo1.getXyczyc() == null ? BigDecimal.ZERO : bizZdCompanyInfo1.getXyczyc();
                    BigDecimal yysr = bizZdCompanyInfo1.getYysr() == null ? BigDecimal.ZERO : bizZdCompanyInfo1.getYysr();

                    BigDecimal lrhjY = bizZdCompanyInfo.getLrhj() == null ? BigDecimal.ZERO : bizZdCompanyInfo.getLrhj();
                    BigDecimal gyzczY = bizZdCompanyInfo.getGyzcz() == null ? BigDecimal.ZERO : bizZdCompanyInfo.getGyzcz();
                    BigDecimal lrzeY = bizZdCompanyInfo.getLrze() == null ? BigDecimal.ZERO : bizZdCompanyInfo.getLrze();
                    BigDecimal xyczycY = bizZdCompanyInfo.getXyczyc() == null ? BigDecimal.ZERO : bizZdCompanyInfo.getXyczyc();
                    BigDecimal yysrY = bizZdCompanyInfo.getYysr() == null ? BigDecimal.ZERO : bizZdCompanyInfo.getYysr();

                    if(lrhjY.compareTo(lrhj) == -1){
                        bizZdCompanyInfo.setLrhjStatus("1");
                    }else{
                        bizZdCompanyInfo.setLrhjStatus("0");
                    }

                    if(gyzczY.compareTo(gyzcz) == -1){
                        bizZdCompanyInfo.setGyzczStatus("1");
                    }else{
                        bizZdCompanyInfo.setGyzczStatus("0");
                    }

                    if(lrzeY.compareTo(lrze) == -1){
                        bizZdCompanyInfo.setLrzeStatus("1");
                    }else{
                        bizZdCompanyInfo.setLrzeStatus("0");
                    }

                    if(xyczycY.compareTo(xyczyc) == -1){
                        bizZdCompanyInfo.setXyczycStatus("1");
                    }else{
                        bizZdCompanyInfo.setXyczycStatus("0");
                    }

                    if(yysrY.compareTo(yysr) == -1){
                        bizZdCompanyInfo.setYysrStatus("1");
                    }else{
                        bizZdCompanyInfo.setYysrStatus("0");
                    }
                }else {
                    bizZdCompanyInfo.setLrhjStatus("0");
                    bizZdCompanyInfo.setGyzczStatus("0");
                    bizZdCompanyInfo.setLrzeStatus("0");
                    bizZdCompanyInfo.setXyczycStatus("0");
                    bizZdCompanyInfo.setYysrStatus("0");
                }
            }else{
                bizZdCompanyInfo.setLrhjStatus("0");
                bizZdCompanyInfo.setGyzczStatus("0");
                bizZdCompanyInfo.setLrzeStatus("0");
                bizZdCompanyInfo.setXyczycStatus("0");
                bizZdCompanyInfo.setYysrStatus("0");
            }
        }
        return bizZdCompanyInfo;
    }
}
